package main.java.com.negromotad.view.tableModelView;

import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;

public class TableModelViewCheckBox extends TableModelView implements
		TableModelListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3131277043128405530L;

	public TableModelViewCheckBox(final String[] cols) {
		super(cols);
		this.setTableModelCol();
	}

	final private void setTableModelCol() {
		final int colsLength = this.getColumnCount();
		final Object[][] data = new Object[13][colsLength];
		data[0][0] = new String("YEAR");
		data[1][0] = new String("JULY");
		data[2][0] = new String("AUGUST");
		data[3][0] = new String("SEPTEMBER");
		data[4][0] = new String("OCTOBER");
		data[5][0] = new String("NOVEMBER");
		data[6][0] = new String("DICEMBER");
		data[7][0] = new String("JANUARY");
		data[8][0] = new String("FEBRUARY");
		data[9][0] = new String("MARCH");
		data[10][0] = new String("APRIL");
		data[11][0] = new String("MAY");
		data[12][0] = new String("JUNE");
		for (int i = 1; i < colsLength; i++) {
			for (int j = 0; j < data.length; j++) {
				data[j][i] = new Boolean(false);
			}
		}
		this.setData(data);

	}

	@Override
	public void tableChanged(TableModelEvent tablemodelevent) {
		int col = tablemodelevent.getColumn();
		int row = tablemodelevent.getFirstRow();
		if (row == 0 && (col == 1 || col == 2 || col == 3)) {
			Object[][] aux = this.getData();
			if ((Boolean) aux[row][col].equals(Boolean.TRUE)) {
				for (int i = 1; i < this.getData().length; i++)
					aux[i][col] = Boolean.TRUE;
			} else {
				for (int i = 1; i < this.getData().length; i++)
					aux[i][col] = Boolean.FALSE;
			}

			this.setData(aux);
		}

	}

}